package com.example.myapplication.ui.fragment

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.myapplication.request.ArticleRequest
import com.example.myapplication.request.CollectRequest
import kotlinx.coroutines.launch

/**
 *首页的viewmodel
 *
 * @author : Kun
 * @date : 2021/6/2
 * @time : 16:02
 */
class HomeViewModel : ViewModel() {
    /**
     * 文章的request
     */
    val articleRequest = ArticleRequest()

    /**
     * 收藏相关的request
     */
    val collectRequest = CollectRequest()

    /**
     * 请求文章列表
     */
    fun requestArticleList(index: Int) {
        viewModelScope.launch {
            articleRequest.requestArticleList(index)
        }
    }

    /**
     * 请求banner
     */
    fun requestBannerList() {
        viewModelScope.launch {
            articleRequest.requestBannerList()
        }
    }

    /**
     * 请求置顶文章
     */
    fun requestTopArticleList() {
        viewModelScope.launch {
            articleRequest.requestTopArticleList()
        }
    }

    /**
     * 新增文章收藏
     */
    fun requestAddCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestAddCollectArticle(id)
        }
    }

    /**
     * 取消文章收藏
     */
    fun requestDelCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestDelCollectArticle(id)
        }
    }
}